<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$id = intval($_RQ['id']);
	$mid = intval($_RQ['mid']);
	if($id){
		$return['bangpai']=pdo_get('jy_jianghu_bangpai',array('id'=>$id));
	}elseif($mid){
		$return['bangpai']=pdo_get('jy_jianghu_bangpai',array('mid'=>$mid));
	}
	$return['bangpai']['title']=cfc('tools')->substr($return['bangpai']['title'],0,20);
	$this->model('model')->getzhanli($return['bangpai']);
	$_SESSION['jianghu_id']=$return['bangpai']['id'];
	if(!$_SESSION['jianghu_id']){
		exi('请选择帮派！','error');
	}
	if($_SESSION['uid']==$return['bangpai']['mid']){
		$return['isboss']=1;
	}
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','mobile','avatar','nickname'));;
	$return['member']=$member;
	$boss=model('core/member')->detail($return['bangpai']['mid'],array('credit1','credit2','credit3','mobile','avatar','nickname'));;
	$boss['nickname']=cfc('tools')->substr($boss['nickname'],0,20);
	$return['boss']=$boss;
	$bangpaipaixu=pdo_count('jy_jianghu_bangpai',array('zhanli >'=>$return['bangpai']['zhanli']),'id');
	$return['bangtitle']=$this->bangpais[$bangpaipaixu];
	$return['bangpai_hao']=$this->bangpai_hao[$bangpaipaixu];
	$return['all_num']=pdo_count('jy_jianghu_myjia',array('jianghu_id'=>$return['bangpai']['id'],'uniacid'=>$_SESSION['uniacid']),'mid');
	$return['isjia']=pdo_count('jy_jianghu_myjia',array('mid'=>$_SESSION['uid'],'jianghu_id'=>$return['bangpai']['id'],'uniacid'=>$_SESSION['uniacid']),'mid');
	//通过帮众分享的可以加入；
	if($_RQ['canjia']==1){
		$return['jiamsg']=$this->model('model')->checkjiabang($return['bangpai']);
	}
	$return['tips']=$return['pluginset']['tips']?:'兄弟们，为了帮派的壮大，每周至少帮忙<巡山呐喊>一次哦！只有通过本帮众分享邀请进来的，才能[加入本帮派]哦！';
	$return['rules']=$this->plugin_setting('rules');
	$canjia=$return['isjia']?1:0;
	$sharelink='jy_jianghu/item//id='.$id.'&canjia='.$canjia.'&fromuser='.$_SESSION['uid'];
	$bangpaititle=$return['bangtitle'].'['.$return['bangpai']['title'].']，大王叫我来巡山啊，我把五岳逛一遍！';
	$share_title=$return['bangpai_hao']?$bangpaititle:$share_title;
	$share_desc=$return['pluginset']['share_desc'];
	$bangpai_hao=$return['bangpai_hao']?$return['bangpai_hao'].'，大侠，加入我们吧，一起快意恩仇！':'';
	$share_desc=$return['bangpai_hao']?$bangpai_hao:$share_desc;
	$return['sharedata']=array(
		'title'=>$share_title?:'大话笑傲江湖，浩然正气，闯江湖！',
		'desc'=>$share_desc?:'这些白云聚了又散，散了又聚，人生离合，亦复如斯--金庸',
		'link'=>custom_url($sharelink,true),
		'imgUrl'=>$return['pluginset']['share_image']?tomedia($return['pluginset']['share_image']):tomedia('../addons/jy_jianghu/resource/images/share.jpg')
	);
	$return['post']=array('id'=>$return['bangpai']['id'],'title'=>$return['bangpai']['title']);
	set_html('title',$return['bangtitle'].$return['bangpai']['title']?:'帮派详情');
	exi($return);
}
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'jianghu_id'=>$_SESSION['jianghu_id']);
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_jianghu_myjia',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	$basic=$return['pluginset'];
	$bangpai=pdo_get('jy_jianghu_bangpai',array('id'=>$_SESSION['jianghu_id']));
	foreach($return['list'] as &$v){
			$v['createtime']=date('Y-m-d H:m:s',$v['createtime']);
			$level=pdo_getcolumn('jy_weishop_member',array('mid'=>$v['mid'],'uniacid'=>$_SESSION['uniacid']),'level');
			//高级长老绑定等级			
			if($basic['gaogroup_id'] && $basic['gaogroup_id']==$level){
				$v['grouptitlle']='高级长老';
				$gaogroup_num++;
			}elseif($basic['zhonggroup_id'] && $basic['zhonggroup_id']==$level){
				$v['grouptitlle']='中级长老';
				$zhonggroup_num++;
			}elseif($basic['digroup_id'] && $basic['digroup_id']==$level){
				$v['grouptitlle']='普通长老';
				$digroup_num++;
			}else{
				$v['grouptitlle']='帮众';
			}
			if($v['mid']==$bangpai['mid']){
				$v['grouptitlle']='帮主';
			}
			$v['member']=cfc('core')->member_show($v['mid']);
	}
	exi($return);
}
if($_RQ['op']=='tuichu'){
	$post=get_postdata();
	if(!$post['id']){
		exi('请选择要退出的帮派！','error');
	}
	$this->model('model')->tuibang($post['id']);
	exi('退出帮派成功！大侠慢走，咋们江湖再见！');
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	if(!$post['title']){
		exi('请输入帮派名称！','erroe');
	}
	pdo_update('jy_jianghu_bangpai',array('title'=>$post['title']),array('id'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
	exi('设置成功！');
}